package com.niit.web.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.niit.bean.Classify;
import com.niit.bean.Question;
import com.niit.service.ClassifyService;
import com.niit.service.QuestionService;
import com.niit.service.impl.ClassifyServiceImpl;
import com.niit.service.impl.QuestionServiceImpl;
import com.niit.utils.Page;
import com.niit.utils.WebKit;

@WebServlet("/ShowMoreQuestionController")
public class ShowMoreQuestionController extends HttpServlet {
	private static final long serialVersionUID = 1L;

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		
		// 查询出所有的问题的分类
		ClassifyService cs = new ClassifyServiceImpl();
		List<Classify> list = cs.findAll();
		request.setAttribute("classify", list);

		
		String classify = request.getParameter("classify");
		String pagenum = request.getParameter("curPage");
		if("".equals(classify)){//防止传值为 classify=""
			classify=null;
		}
		QuestionService qs = new QuestionServiceImpl();
		Page<Question> page = qs.getPageByClassify(classify, pagenum, WebKit.getServletURI(request));
		request.setAttribute("page", page);
		request.setAttribute("classkind", classify);
		request.getRequestDispatcher("/jsp/user/plaza/question.jsp").forward(
				request, response);
	}
}
